package com.graduation.rescuematerial.controller.system;

import com.graduation.rescuematerial.service.ApplyMaterialService;
import com.graduation.rescuematerial.service.UserService;
import com.graduation.rescuematerial.vo.FuzzyOrderQueryVo;
import com.graduation.rescuematerial.vo.RespBean;
import com.graduation.rescuematerial.vo.RespBeanEnum;
import com.graduation.rescuematerial.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:CaiShuangLian
 * @FileName:
 * @Date:Created in  2022/4/29 14:06
 * @Version:
 * @Description:TODO
 */
@RestController
@RequestMapping("sys/order")
@Api(tags = "系统管理员——订单模块")
public class SysApplyMaterialController {

    @Autowired
    private ApplyMaterialService applyMaterialService;
    @Autowired
    private UserService userService;

    @ApiOperation("订单列表")
    @PostMapping("/all")
    @ResponseBody
    public RespBean getAll(@RequestBody String ticket, HttpServletRequest request, HttpServletResponse response){
        if(ticket!=null && !ticket.isEmpty()){
            //根据cookie获取用户信息
            UserVo userVo=userService.getUserByCookie(ticket,request,response);
            if(userVo!=null && userVo.getAction().equals("system_administrator")){
                return applyMaterialService.getAll();
            }
            return RespBean.error(RespBeanEnum.NO_OPERATION_PERMISSION,"非系统管理员，无法查看");
        }
        return RespBean.error(RespBeanEnum.ILLEGAL_OPERATION);
    }

    @ApiOperation("联合查询")
    @PostMapping("/union/query")
    @ResponseBody
    public RespBean unionQuery(@RequestBody FuzzyOrderQueryVo fuzzyOrderQueryVo, HttpServletRequest request, HttpServletResponse response){
        String ticket=fuzzyOrderQueryVo.getTicket();
        if(ticket!=null && !ticket.isEmpty()){
            //根据cookie获取用户信息
            UserVo userVo=userService.getUserByCookie(ticket,request,response);
            if(userVo!=null && userVo.getAction().equals("system_administrator")){
                return applyMaterialService.unionQuery(fuzzyOrderQueryVo);
            }
            return RespBean.error(RespBeanEnum.NO_OPERATION_PERMISSION,"非系统管理员，无法查看");
        }
        return RespBean.error(RespBeanEnum.ILLEGAL_OPERATION);
    }




}
